using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Org.Loon.Framework.Xna.Game.Action.Scripting
{
    public class StackFrame
    {

        private Script script;

        private int count = 0;

        private int wait = 0;

        private int programCounter = 0;

        private Function currentFunction;

        public StackFrame(Script script)
        {
            this.script = script;
            this.programCounter = 0;
        }

        public void NewTick()
        {
            count++;
        }

        public bool HasNext()
        {
            return ((wait <= count) && (programCounter < script.Size()));
        }

        public Function Next()
        {
            currentFunction = script.GetFunction(programCounter);
            if (currentFunction is WaitFunction)
            {
                count = 0;
                wait = ((WaitFunction)currentFunction).GetWait();
            }
            programCounter++;
            return currentFunction;
        }

        public bool IsComplete()
        {
            return script == null ? true : (programCounter >= script.Size());
        }

        public Script GetScript()
        {
            return script;
        }

    }
}
